package com.dexilaonian.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.ui.MyRecyclerViewOnclickInterface;

import java.util.List;

public class HouseAdapter extends RecyclerView.Adapter<HouseAdapter.MyViewHolde>{

    private final Context context;
    private final List<String> mList_house;

    public MyRecyclerViewOnclickInterface mOnItemClickLitener;

    public void setmOnItemClickLitener(MyRecyclerViewOnclickInterface mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public HouseAdapter(Context context, List<String> list_project) {
        this.context = context;
        mList_house = list_project;
    }

    @Override
    public MyViewHolde onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        MyViewHolde myViewHolde = new MyViewHolde(inflater.inflate(R.layout.recyclerview_house, parent, false));
        return myViewHolde;
    }

    @Override
    public void onBindViewHolder(final MyViewHolde holder, int position) {
        holder.tvItemhouse.setText(mList_house.get(position));
        holder.tvMinhouse.setText(mList_house.get(position));
       // ImageLoader.display(context,new_url,holder.ivRecycler);
        if (mOnItemClickLitener != null) {
        holder.tvItemhouse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int layoutPosition = holder.getLayoutPosition();
                mOnItemClickLitener.onItemClick(holder.tvItemhouse, layoutPosition);
            }
        });
        }
    }

    @Override
    public int getItemCount() {
        return mList_house.size();
    }
    class MyViewHolde extends RecyclerView.ViewHolder{

        TextView tvMinhouse;
        TextView tvItemhouse;
        ImageView ivRecycler;

        public MyViewHolde(View itemView) {
            super(itemView);
            tvItemhouse = (TextView) itemView.findViewById(R.id.tv_title_hosue);
            tvMinhouse = (TextView) itemView.findViewById(R.id.tv_min_house);
            ivRecycler = (ImageView) itemView.findViewById(R.id.iv_house);
        }
    }
}
